# Copyright 2022 The GPflow Contributors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from pathlib import Path
from unittest.mock import Mock

import pytest

from benchmark.metadata import BenchmarkMetadata
from benchmark.paths import setup_dest


@pytest.mark.parametrize("exist", [False, True])
@pytest.mark.parametrize("no_subdir", [False, True])
def test_setup_dest(tmp_path: Path, exist: bool, no_subdir: bool) -> None:
    metadata = Mock(BenchmarkMetadata)
    metadata.run_id = "test_run_id"
    dest = tmp_path / "dest"
    expected = dest if no_subdir else (dest / "test_run_id")

    if exist:
        expected.mkdir(parents=True, exist_ok=True)
        with pytest.raises(FileExistsError):
            setup_dest(metadata, dest, no_subdir=no_subdir)
    else:
        expected.parent.mkdir(parents=True, exist_ok=True)
        assert expected == setup_dest(metadata, dest, no_subdir=no_subdir)
